package com.yunzhi.medical.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunzhi.medical.mapper.CheckItemMapper;
import com.yunzhi.medical.pojo.CheckItem;
import com.yunzhi.medical.CheckItemService;
import com.yunzhi.medical.utils.MessageConstant;
import com.yunzhi.medical.utils.PageResult;
import com.yunzhi.medical.utils.QueryPageBean;
import com.yunzhi.medical.utils.Result;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author :Mikey
 * @description :
 * @create :2022-06-25 10:57:00
 */
@Service
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;

    @Override
    public Result addCheckItemInfo(CheckItem checkItem) {
        boolean flag=checkItemMapper.insertCheckItem(checkItem) > 0;
        if (flag) {
            return new Result(flag, MessageConstant.ADD_CHECKGROUP_SUCCESS);
        }else{
            return new Result(flag, MessageConstant.ADD_CHECKGROUP_FAIL);
        }

    }

    @Override
    public PageResult findPageInfo(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        List<CheckItem> list = null;
        if (queryPageBean.getQueryString() != null && queryPageBean.getQueryString().length() > 0) {
            list = checkItemMapper.findLikeItemInfo(queryPageBean.getQueryString());
        } else {
            list = checkItemMapper.findItemInfo();
        }
        PageInfo<CheckItem> checkItemPageInfo = new PageInfo<>(list);
        return new PageResult(checkItemPageInfo.getTotal(), checkItemPageInfo.getList());
    }

    @Override
    public Result findCkeckItem(Integer id) {
        boolean flag = false;
        CheckItem checkItem = checkItemMapper.findCkeckItem(id);
        flag = checkItem != null;
        if (flag) {
            return new Result(flag, MessageConstant.QUERY_CHECKGROUP_SUCCESS, checkItem);
        } else {
            return new Result(flag, MessageConstant.QUERY_CHECKGROUP_FAIL, checkItem);
        }
    }

    @Override
    public Result updateCheckItem(CheckItem checkItem) {
        boolean flag = false;
        flag = checkItemMapper.updateCheckItem(checkItem) > 0;
        if (flag) {
            return new Result(flag, MessageConstant.EDIT_CHECKITEM_SUCCESS);
        } else {
            return new Result(flag, MessageConstant.EDIT_CHECKITEM_FAIL);
        }
    }

    @Override
    public Result deleteCheckItem(Integer id) {
        boolean flag = false;
        flag = checkItemMapper.deleteCheckItem(id) > 0;
        System.out.println(checkItemMapper.deleteCheckItem(id));
        if (flag) {
            return new Result(flag, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
        } else {
            return new Result(flag, MessageConstant.DELETE_CHECKGROUP_FAIL);
        }
    }
}
